package GameLogic

import (
	"GameLogic/ECMap"
	"git.oschina.net/yangdao/extlib/math3d"

	"git.oschina.net/yangdao/SGLisp/parse"

	"git.oschina.net/yangdao/SGLisp"

	"git.oschina.net/yangdao/GameLib/Area"
	"git.oschina.net/yangdao/GameLib/Unit"
)

var MoverManager *Unit.MoverManager

func Load() {
	MoverManager = &Unit.MoverManager{}
	MoverManager.Init()
	Unit.BehaviorManager.Init()
	Unit.AbilityManager.Init()

	ECMap.Load(`../../Common/Table/Map/`)

	Unit.EffectManager.Load(SGLisp.MainContext)
	Unit.EffectManager.RegisterEffect("EffectDamage", CreateEffectDamage)
	Unit.EffectManager.RegisterEffect("EffectSearchUnit", CreateEffectSearchUnit)
	Unit.EffectManager.RegisterEffect("EffectLaunchUnit", CreateEffectLaunchUnit)
	Unit.EffectManager.RegisterEffect("EffectUnitState", createEfffectUnitState)

	areaContext := Area.AreaContext{}
	areaContext.Init(nil)
	SGLisp.MainContext.Import(areaContext.Context, "")
	SGLisp.MainContext.Import(MoverManager.Context, "")
	SGLisp.MainContext.Import(Unit.BehaviorManager.Context, "")
	SGLisp.MainContext.Import(Unit.EffectManager.Context, "")
	SGLisp.MainContext.Import(Unit.AbilityManager.Context, "")

	SGLisp.MainContext.DefineFunc("vec3", _vec3)

	Unit.LispTables.Load(`../../Common/Table/`, SGLisp.MainContext)
}

func _vec3(args []parse.Node, context *SGLisp.Context) parse.Node {
	args = SGLisp.EvalArgs(args, context)
	v3 := &math3d.Vec3{
		X: SGLisp.EvalNode(args[0], context).(float64),
		Y: SGLisp.EvalNode(args[1], context).(float64),
		Z: SGLisp.EvalNode(args[2], context).(float64),
	}
	return &parse.ObjectNode{Val: v3}
}
